package  
{
	import net.flashpunk.World;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.World;
	import net.flashpunk.utils.Input;
	import net.flashpunk.FP;
	
	/**
	 * ...
	 * @author Donatello
	 */
	public class FourthScene extends World
	{
		[Embed(source = "img/kitchen.png")]	private const IMG_BACK:Class;
		private var imgBack:Image;
		private var player:Player;
		private var girl:Girl;
		private var pressed:Boolean = false;
		private var sentido:Number;
		private var time:Number = 3.0;
		
		public function FourthScene() 
		{
			imgBack = new Image(IMG_BACK);
			imgBack.x = 0;
			imgBack.y = 0;
			addGraphic(imgBack);
			
			player = new Player(70, 300);
			girl = new Girl(0, 300);
			
			sentido = 200;
					
			add(girl);
			add(player);
			
			player.kitchen = true;
			
		}
		
		override public function update():void
		{
			if (player.y == 300)
			{
					sentido = 200;
			}
			else sentido = -200;
			
			time += FP.elapsed;
			var aux:Number = 0;
			
			if(player.x<700)
			{
				if (time >= 3)
				{
					if (FP.rand(2) < 1)
						aux = 300;
					else aux = 500;
						
					add(new KitchenGuy(800, aux));
					
					time = 0.0;
				}
			}
			
			if(Input.mousePressed && !pressed)
			{
				pressed = true;
				player.y += sentido;
				girl.y += sentido;
			
				
			}
			
			if (Input.mouseReleased)
			{	
				pressed = false;
				sentido *= -1;
			}
			
			
			if (player.collide("KitchenGuy", player.x, player.y))
			{
				FP.world = new FourthScene();
				removeAll();
			}
			if (girl.x > FP.screen.width)
			{
				FP.world = new FifthScene();
				removeAll();
			}
			
			super.update();
			
		}
		
	}

}